import { IFrUIContainer } from "../core/IFrUIContainer";
import { IDispose } from "../../gengine/core/IDispose";
import { ObjEventListerTool } from "../utils/ObjEventListerTool";
import { UICompomentPool } from "../utils/UICompomentPool";
import { Vector } from "../../../__AS3__/vec/Vector";
type int = number;
//class GSprite
    
    export  class GSprite /* flash.display.Sprite */ implements IFrUIContainer
    {
        constructor()
        {
            
            this._uiDisposeVec = new Vector.<IDispose>();
            this.configUI();
            return;
        }

        protected pushUIToDisposeVec(arg1: IDispose): void
        {
            this._uiDisposeVec.push(arg1);
            return;
        }

        protected onAddToStageCreate(arg1: Object /* flash.events.Event */): void
        {
            this.createDisposedChildren();
            return;
        }

        protected onRemoveFromStageDispose(arg1: Object /* flash.events.Event */): void
        {
            this.disposeChildren();
            return;
        }

        public configEventListener(arg1: string, arg2: Function, arg3: Boolean=false, arg4: int=0, arg5: Boolean=false): void
        {
            ObjEventListerTool.addObjEvent(this, arg1, arg2, arg3);
            addEventListener(arg1, arg2, arg3, arg4, arg5);
            return;
        }

        public /* override */ removeEventListener(arg1: string, arg2: Function, arg3: Boolean=false): void
        {
            ObjEventListerTool.removeObjEvent(this, arg1, arg2, arg3);
            super.removeEventListener(arg1, arg2, arg3);
            return;
        }

        public get isDisposed(): Boolean
        {
            return this._disposed;
        }

        protected configUI(): void
        {
            this.createDisposedChildren();
            return;
        }

        public dispose(arg1: Boolean=true): void
        {
            this.disposeChildren();
            ObjEventListerTool.delObjEvent(this);
            this.x = 0;
            this.y = 0;
            this.mouseEnabled = true;
            this.mouseChildren = true;
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            if (arg1) 
            {
                UICompomentPool.disposeUICompoment(this);
            }
            return;
        }

        protected disposeChildren(arg1: Boolean=true): void
        {
            var loc1=null;
            if (!this._disposed) 
            {
                this._disposed = true;
                var loc2=0;
                var loc3=this._uiDisposeVec;
                for(loc1 of loc3) 
                {
                    loc1.dispose(arg1);
                }
                this._uiDisposeVec = new Vector.<IDispose>();
                this.disposeImpl(arg1);
            }
            return;
        }

        public createDisposedChildren(): void
        {
            if (!this._disposed) 
            {
                return;
            }
            this._disposed = false;
            this.createDisposedChildrenImpl();
            return;
        }

        protected disposeImpl(arg1: Boolean=true): void
        {
            return;
        }

        protected createDisposedChildrenImpl(): void
        {
            return;
        }

        private /* var */_uiDisposeVec: Vector.<IDispose>;

        protected /* var */_disposed: Boolean=true;
    }
